home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 2.toast / pc / sample code / platforms and tools / installer / userfunction gestalt / userchkgestaltfunction.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-09-28  |  3.1 KB  |  103 lines

  1. /*
  2.     File:        UserChkGestaltFunction.c
  3.  
  4.     Contains:    Use as a alternate means of identifying whether a Gestalt selector
  5.                  is available.  The CheckGestalt clause requires the scriptor to enter
  6.                 all valid Gestalt selector results.  This poses a future compatibility
  7.                 problem in that one would like to simply know that a gestalt selector
  8.                 exists and not have to worry about matching the result in order to pass
  9.                 the clause.  This user function simply requires that the scriptor pass in 
  10.                 the gestalt selector to check for.  A true result is returned if the selector
  11.                  is found, false otherwise or if the Gestalt trap was not available.
  12.  
  13.     Written by: Rich Kubota    
  14.  
  15.     Copyright:    Copyright © 1988-1999 by Apple Computer, Inc., All Rights Reserved.
  16.  
  17.                 You may incorporate this Apple sample source code into your program(s) without
  18.                 restriction. This Apple sample source code has been provided "AS IS" and the
  19.                 responsibility for its operation is yours. You are not permitted to redistribute
  20.                 this Apple sample source code as "Apple sample source code" after having made
  21.                 changes. If you're going to re-distribute the source, we require that you make
  22.                 it clear in the source that the code was descended from Apple sample source
  23.                 code, but that you've made changes.
  24.  
  25.     Change History (most recent first):
  26.                 8/18/1999    Karl Groethe    Updated for Metrowerks Codewarror Pro 2.1
  27.                 
  28.  
  29. */
  30. #if 0
  31. c -b UserChkGestaltFunction.c
  32. Link -ra =resPurgeable -rt infn=1002 -rn -m USERCHKGESTALTFUNCTION -t rsrc -c RSED ∂
  33.         UserChkGestaltFunction.c.o ∂
  34.         "{Libraries}"Interface.o ∂
  35.         -o UserChkGestaltFunction.rsrc
  36. #endif
  37.  
  38. #include <Types.h>
  39. #include <Traps.h>
  40. #include <OSUtils.h>
  41. #include <GestaltEqu.h>
  42. #include <Patches.h>
  43. #include "UserChkGestaltFunction.h"
  44. /******************  function prototypes  *********************/
  45.  
  46. short         NumToolboxTraps(void);
  47. TrapType     GetTrapType(unsigned short theTrap);
  48. Boolean     TrapAvailable(unsigned short theTrap);
  49.  
  50. /**************************************************************/
  51.  
  52. pascal Boolean UserChkGestaltFunction(short targetVRefNum, long blessedID, long selector)
  53. {
  54. #pragma unused (blessedID, targetVRefNum)
  55.  
  56.     OSErr    err;
  57.     long    result;
  58.     
  59.     if (TrapAvailable(_Gestalt))        // check whether the Gestalt trap is available
  60.     {
  61.         err = Gestalt((OSType)selector, &result);    // pass the selector to the Gestalt call
  62.         return (err == noErr);        // return result
  63.     }
  64.     else
  65.         return false;                // gestalt not found, return false
  66. }
  67.  
  68. /******** The following code is from IM VI *******/
  69.  
  70. short NumToolboxTraps(void)
  71. {    
  72.     if (NGetTrapAddress(_InitGraf, ToolTrap) == 
  73.         NGetTrapAddress(0xAA6E, ToolTrap))
  74.         return(0x200);
  75.     else
  76.         return(0x400);
  77. }
  78.  
  79. #define TrapMask    0x0800
  80.  
  81. TrapType GetTrapType(unsigned short theTrap)
  82. {
  83.     if (theTrap & TrapMask)
  84.         return (ToolTrap);
  85.     else
  86.         return (OSTrap);
  87. }
  88.  
  89. Boolean TrapAvailable(unsigned short theTrap)
  90. {
  91.     TrapType    theType;
  92.     
  93.     theType = GetTrapType(theTrap);
  94.     if (theType == ToolTrap) {
  95.         theTrap &= 0x07FF;
  96.         if (theTrap >= NumToolboxTraps())
  97.             theTrap = _Unimplemented;
  98.     }
  99.     
  100.     return (NGetTrapAddress(theTrap, theType) != 
  101.             NGetTrapAddress(_Unimplemented, ToolTrap));
  102. }
  103.